<?php
require_once(FWK_EXCEPTION."CustonException.class.php");
require_once(BIB_ACTIVE_RECORD);
require_once(FWK_MODEL."AbsModelDao.class.php");
require_once(FWK_UTIL."FormataDatas.class.php");
/**
 * @author André Coura <andreccls@gmail.com>
 * @since 1.0 - 04/06/2012
 */
class CategoriaBlog extends AbsModelDao{

	public $_table = "blog_categoria";

	public $_id = "id_categoria";

	public function getListaGrid($limitIni=0, $numRegs=15, $count=false){
		$strQuery = "SELECT ";
		if($count){
			$strQuery.= " count(id_categoria) ";
		}else{
			$strQuery .= "id_categoria, titulo_categoria as 'Categoria' ";
		}
		$strQuery .= " FROM
					 		".$this->_table;
		if(!$count){
			$strQuery .= " LIMIT
								".$limitIni." ,".$numRegs;
		}
		
		$arrRet = ControlDB::getAll($strQuery,3);
		return $arrRet;
	}

	public function getCategoria($id){
		$strQuery = "SELECT
							id_categoria, titulo_categoria, desc_categoria
					 FROM 
					 		".$this->_table. " 
					 WHERE
					 	id_categoria = '".$id."'";
		$arrRet = ControlDB::getAll($strQuery,3);
		return $arrRet;
	}
	

	public function getDadosCombo(){
		$strQuery = "SELECT
							id_categoria, titulo_categoria
					 FROM 
					 		".$this->_table;
		$arrRet = ControlDB::getAll($strQuery,3);
		return $arrRet;
	}


	public function alterar($id=null,$post,$file){
		try{
			self::salvaPostAutoUtf8($post);
			$this->id_categoria = $id;
				
			//campos default para todos os daos (historico de edição de arquivos)
			$this->data_alteracao = date("Y-m-d H:i:s");
			$this->id_usuario = parent::getUsuarioSessao()->getIdUsuario();
			self::replace();
			if(self::ErrorMsg()){
				print("<pre>");
				print_r($post);
				die("<br/><br /><h1>".self::ErrorMsg()."</h1>");
			}
		}catch(DaoException $e){
			throw new CustonException($e->getMensagem());
		}
	}
}
?>